package cn.marinda.spritefragment.commands;

import cn.marinda.spritefragment.data.ConfigManager;
import cn.marinda.spritefragment.data.DataInterface;
import cn.marinda.spritefragment.util.PlayerUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public class GiveCommand implements CommandsObject {
    /*
    giveCommand命令
     */
    private ConfigManager gm = null;

    public GiveCommand() {

    }

    @Override
    public boolean registerCommands(String cmd, String[] args) {
        if (args[0].equalsIgnoreCase("give")) {
            String playerName = args[1];
            Player player = Bukkit.getPlayer(playerName);
            try {
                gm = new ConfigManager();
                DataInterface di = gm.getItemData();
                ItemStack item = di.getItems(args[2]);
                int number = Integer.parseInt(args[3]);
                item.setAmount(number);
                if (player.getInventory().firstEmpty() == -1) {
                    player.sendMessage("§6" + gm.getConfigData().getPrefix() + "背包满了");
                    return true;
                }
                player.getInventory().addItem(item);
                player.sendMessage("§6" + gm.getConfigData().getPrefix() + "§a你获得了§b" + args[2] + "物品");
                return true;
            } catch (NullPointerException e) {
                player.sendMessage("§6" + gm.getConfigData().getPrefix() + "§c没有这个代号存在哦");
                return true;
            }
        }
        return false;
    }
}
